package com.pactera.madp.cp.controller.oms.contactfieldpivot;

import com.pactera.madp.common.core.util.R;
import com.pactera.madp.common.log.annotation.SysLog;
import com.pactera.madp.cp.api.dto.contactfieldpivot.ContactFieldPivotDto;
import com.pactera.madp.cp.api.dto.workcontacttag.WorkContactTagDTO;
import com.pactera.madp.cp.api.vo.ContactFieldPivotVO;
import com.pactera.madp.cp.service.IWorkContactFieldPivotService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.pactera.madp.common.core.util.R.ok;

/**
 * @author zhaojinjian
 * @ClassName ContactFieldPivotController.java
 * @Description TODO
 * @createTime 2020/12/24 16:41
 */
@RestController
@AllArgsConstructor
@RequestMapping("/contactfieldpivot")
@Api(value = "contactfieldpivot", tags = "客户详情 - 用户画像")
public class ContactFieldPivotController {

    private final IWorkContactFieldPivotService contactFieldPivotService;

    /**
     * @description 客户 - 客户详情 - 用户画像
     * @author zhaojinjian
     * @createTime 2020/12/24 18:05
     */
    @GetMapping("/{contactId}")
    @ApiOperation(value = "客户详情 - 用户画像")
    @ApiImplicitParams({
            @ApiImplicitParam(name="contactId",value="客户id",dataType="Integer")
    })
    public R<List<ContactFieldPivotVO>> getContactFieldPivotList(@PathVariable Integer contactId) {
        if (contactId == null) {
           R.failed("非法的参数");
        }
        return ok(contactFieldPivotService.getContactFieldPivotList(contactId));
    }

    /**
     * @description 客户 - 客户详情 - 编辑用户画像
     * @author zhaojinjian
     * @createTime 2020/12/24 18:15
     */
    @SysLog("客户详情 - 编辑用户画像")
    @PutMapping
    @ApiOperation(value = "客户详情 - 编辑用户画像")
    public R<Boolean> updateContactFieldPivot(@RequestBody ContactFieldPivotDto param) {
        return contactFieldPivotService.updateContactFieldPivot(param) ? R.ok(Boolean.TRUE,"修改成功") : R.failed(Boolean.FALSE,"修改失败");
    }

    /**
     * 编辑企业客户标签
     *
     */
    @SysLog("企业标签编辑")
    @PutMapping("/label_put")
    @ApiOperation(value = "企业标签编辑")
    public R labelPut(@RequestBody WorkContactTagDTO workContactTagDTO){
        contactFieldPivotService.labelPut(workContactTagDTO);
            return R.ok();
    }

}
